
import math

# 分页控制
def page_paginator(limit, page, count):
    page_data = {}
    if not all([limit, page, count]):
        return limit, page, count
    # math提供函数，向上取整
    count_page = math.ceil(count / limit)
    page_data['count_page'] = count_page
    if page == 1:
        has_previous = 0
        has_previous_num = 1
    elif page <= count_page and page > 1:
        has_previous = 1
        has_previous_num = page - 1
    else:
        has_previous = 0
        has_previous_num = 1
    page_data['has_previous'] = has_previous
    page_data['has_previous_num'] = has_previous_num
    if page < count_page and page == 1:
        has_next = 1
        has_next_num = page + 1
    elif page < count_page and page > 1:
        has_next = 1
        has_next_num = page + 1
    elif page == count_page:
        has_next = 0
        has_next_num = count_page
    else:
        has_next = 0
        has_next_num = count_page
    page_data['has_next'] = has_next
    page_data['has_next_num'] = has_next_num
    return page_data